//
//  MainTabBarController.m
//  微博
//
//  Created by 杨佩璋 on 15/6/24.
//  Copyright (c) 2015年 杨佩璋. All rights reserved.
//

#import "MainTabBarController.h"
#import "MainNavigationController.h"
#import "MyTabBar.h"
#import "FestivalViewController.h"
#import "NowBeShownViewController.h"
#import "WillBeShownViewController.h"
#import "WeChooseViewController.h"
#import "CinemaViewController.h"
//#import "MyBar.h"

@interface MainTabBarController ()

@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //   设置子控制器
    FestivalViewController *festival = [[FestivalViewController alloc] init];
    UIImage *image = [UIImage imageNamed:@"iconfont-xinwen(1)"];
    [self addChildVC:festival WithTitle:@"电影新鲜事" image:image selectedImage:image];
    self.firstVC = festival;
    [festival release];
    
    WeChooseViewController *wechoose = [[WeChooseViewController alloc] init];
    UIImage *image2 = [UIImage imageNamed:@"iconfont-yuedu(1)"];
    [self addChildVC:wechoose WithTitle:@"精选" image:image2 selectedImage:image2];
    [wechoose release];
    
    NowBeShownViewController *nowBeShown = [[NowBeShownViewController alloc] init];
    UIImage *image3 = [UIImage imageNamed:@"iconfont-dianying(4)"];
    [self addChildVC:nowBeShown WithTitle:@"正在上映" image:image3 selectedImage:image3];
    [nowBeShown release];
    
    
    WillBeShownViewController *willBeShown = [[WillBeShownViewController alloc] init];
    UIImage *image4 = [UIImage imageNamed:@"iconfont-dianying(5)"];
    [self addChildVC:willBeShown WithTitle:@"即将上映" image:image4 selectedImage:image4];
    [willBeShown release];
    
    CinemaViewController *cinema = [[CinemaViewController alloc] init];
    UIImage *image5 = [UIImage imageNamed:@"iconfont-tabyingyuan(1)"];
    [self addChildVC:cinema WithTitle:@"影院" image:image5 selectedImage:image5];
    [cinema release];
    
//    self.selectedIndex = 2 ;
//    MyBar *mybar = [[MyBar alloc] init];
//    [self setValue:mybar forKey:@"tabBar"];
    
}

-(void)addChildVC:(UIViewController *)childVC WithTitle:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage
{
    childVC.title = title; // 同时设置tabBar navigationBar 的标题。
    childVC.tabBarItem.image = image;
    UIImage *image1 = selectedImage;
    UIImage *newImage1 = [image1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVC.tabBarItem.selectedImage = newImage1;
    NSDictionary *selectedtextColorDic = @{NSForegroundColorAttributeName:[UIColor orangeColor]};
    [childVC.tabBarItem setTitleTextAttributes:selectedtextColorDic forState:UIControlStateSelected];
    NSDictionary *textColorDic = @{NSForegroundColorAttributeName:RGBColor(123, 123, 123)};
    [childVC.tabBarItem setTitleTextAttributes:textColorDic forState:UIControlStateNormal];
    
    MainNavigationController *navc = [[MainNavigationController alloc] initWithRootViewController:childVC];
    [self addChildViewController:navc];
    [navc release];
}


#pragma mark - HWTabBarDelegate代理方法
- (void)tabBarDidClickPlusButton:(MyTabBar *)tabBar
{
    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor redColor];
    [self presentViewController:vc animated:YES completion:nil];
    [vc release];
}


@end
